Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

Use the Run function in opensearch

Why is it important?

Migrate modules to the new API, improving consistency and leveraging the latest testcontainers functionality.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner October 7, 2025 15:40
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 7, 2025
@netlify
Copy link

netlify bot commented Oct 7, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 0472ff8
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68e563cbc6a232000826c156
😎 Deploy Preview https://deploy-preview-3423--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

Summary by CodeRabbit

  • New Features
    • Support for configurable, dynamic credentials when starting OpenSearch containers.
  • Bug Fixes
    • More reliable startup by using an authenticated health check with a clear timeout and expected response.
  • Refactor
    • Options now perform validation and can return errors, improving configuration safety.
    • Improved error messages for option application and container startup to aid troubleshooting.
    • Internal orchestration updated while preserving the existing public startup entry point and customization behavior.

Walkthrough

Reworks OpenSearch module to build container options via defaults and applied Option functions (now error-returning), injects dynamic credentials into env and wait strategy, and uses testcontainers.Run with an HTTP basic-auth readiness check; updates error wrapping and preserves appended customizers.

Changes

Cohort / File(s) Summary of changes
OpenSearch Run refactor
modules/opensearch/opensearch.go
Replace manual GenericContainer/ContainerRequest with building moduleOpts from defaultOptions(), add env/ports/host ulimits, inject dynamic settings.Username/settings.Password, configure an HTTP wait strategy (GET / on 9200, 200 check, basic-auth, tagline matcher, startup timeout), append incoming opts, call testcontainers.Run(ctx, img, moduleOpts...), and wrap errors (apply option: ..., run opensearch: ...). Removed hardcoded OPENSEARCH_* defaults.
Option signature & constructors
modules/opensearch/options.go
Change type Option from func(*Options) to func(*Options) error; update WithUsername/WithPassword to return closures that set fields and return nil; Option.Customize remains to satisfy ContainerCustomizer but now aligns with error-returning signature.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Run as OpenSearch.Run
  participant TC as testcontainers.Run
  participant C as Container
  participant OS as OpenSearch
  participant WS as WaitStrategy

  Caller->>Run: Run(ctx, image, opts...)
  Run->>Run: defaultOptions() → moduleOpts
  Run->>Run: apply Option(...) (now returns error)
  Run->>Run: inject env (USERNAME/PASSWORD), ports, ulimits
  Run->>Run: configure WaitStrategy (HTTP GET "/", port 9200, 200, basic-auth, tagline match)
  Run->>TC: testcontainers.Run(ctx, image, moduleOpts + opts...)
  TC->>C: create & start container
  par startup readiness
    C->>OS: start process
    WS->>OS: HTTP GET "/" with basic auth
    OS-->>WS: 200 OK + body
    WS->>WS: validate tagline contains "OpenSearch"
  end
  TC-->>Run: container handle or error
  Run-->>Caller: return container or wrapped error ("run opensearch: ...")
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

I hopped through envs and opts with care,
Planted usernames and secrets there.
I waited on HTTP, matched the line,
Then watched the container start just fine.
A rabbit's patch: tidy, swift, and fair. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the key change of migrating the OpenSearch module to use the new Run function and correctly indicates a breaking change, making it concise and focused.
Description Check ✅ Passed The description succinctly explains that this PR updates the OpenSearch module to use the Run function, clarifies the importance of migrating to the new API for consistency, and links the related upstream issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25897bd and 6d2e169.

📒 Files selected for processing (1)
  • modules/opensearch/opensearch.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/opensearch/opensearch.go (3)
modules/opensearch/options.go (1)
  • Option (22-22)
options.go (5)
  • ContainerCustomizer (22-24)
  • WithEnv (75-85)
  • WithExposedPorts (454-459)
  • WithHostConfigModifier (88-94)
  • WithWaitStrategy (366-368)
wait/http.go (1)
  • ForHTTP (149-151)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test (1.24.x, modules/opensearch) / test: modules/opensearch/1.24.x
  • GitHub Check: test (1.25.x, modules/opensearch) / test: modules/opensearch/1.25.x
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
modules/opensearch/opensearch.go (3)

74-99: Comprehensive wait strategy ensures container readiness.

The wait strategy is well-designed with multiple checks:

  • HTTP endpoint verification
  • Basic authentication
  • Response content validation (OpenSearch tagline)

The 120-second timeout is appropriate given the comprehensive checks. The response matcher correctly handles errors by returning false when body reading or JSON unmarshaling fails.


102-102: Correct placement preserves user customization.

Appending incoming opts after moduleOpts ensures that user-provided customizers can override module defaults, which is the expected behavior.


104-114: Clean migration to new API.

The refactoring successfully migrates to testcontainers.Run with proper error handling and container construction. The error message provides clear context.

@mdelapenya mdelapenya force-pushed the use-run-claude-opensearch branch from 6d2e169 to 6039a3c Compare October 7, 2025 16:14
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@mdelapenya mdelapenya force-pushed the use-run-claude-opensearch branch from 6039a3c to 0472ff8 Compare October 7, 2025 19:02
@mdelapenya mdelapenya changed the title chore(opensearch): use Run function chore(opensearch)!: use Run function Oct 7, 2025
@mdelapenya mdelapenya added breaking change Causing compatibility issues. and removed chore Changes that do not impact the existing functionality labels Oct 7, 2025
@mdelapenya mdelapenya self-assigned this Oct 7, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
modules/opensearch/opensearch.go (1)

38-46: Type assertion is valid; past review comment appears outdated.

The type assertion opt.(Option) is correct. Looking at options.go line 19, there's a compile-time check confirming that Option implements ContainerCustomizer:

var _ testcontainers.ContainerCustomizer = (*Option)(nil)

The Customize method is defined on lines 24-28 of options.go. The pattern here extracts settings from Option instances before building the module configuration, which is the intended design. Error wrapping with "apply option: %w" is appropriate.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d2e169 and 0472ff8.

📒 Files selected for processing (2)
  • modules/opensearch/opensearch.go (2 hunks)
  • modules/opensearch/options.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
modules/opensearch/opensearch.go (4)
modules/opensearch/options.go (1)
  • Option (22-22)
options.go (5)
  • ContainerCustomizer (22-24)
  • WithEnv (75-85)
  • WithExposedPorts (454-459)
  • WithHostConfigModifier (88-94)
  • WithWaitStrategy (366-368)
wait/http.go (1)
  • ForHTTP (149-151)
modules/neo4j/neo4j.go (1)
  • Run (39-77)
modules/opensearch/options.go (2)
modules/elasticsearch/options.go (2)
  • Options (10-15)
  • Option (27-27)
modules/gcloud/gcloud.go (1)
  • Option (65-65)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test (1.24.x, modules/opensearch) / test: modules/opensearch/1.24.x
  • GitHub Check: test (1.25.x, modules/opensearch) / test: modules/opensearch/1.25.x
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
modules/opensearch/options.go (1)

22-43: LGTM! Error-returning options align with other modules.

The change from func(*Options) to func(*Options) error is consistent with the pattern used in other modules (e.g., Elasticsearch). The Option functions currently return nil, which is appropriate since credential-setting operations don't fail. The Customize method remains a NOOP because the actual option application happens in the Run function (opensearch.go lines 40-46), where options are applied to the settings struct rather than directly customizing the container request.

Based on learnings from relevant code snippets showing the Elasticsearch module uses the same pattern.

modules/opensearch/opensearch.go (2)

76-101: Robust wait strategy implementation.

The wait strategy is comprehensive:

  • HTTP health check on the root path
  • Status code validation (HTTP 200)
  • Response matcher validates the OpenSearch tagline for correctness
  • Reasonable 120-second startup timeout
  • TLS explicitly disabled with clear documentation

The basic auth concern was already flagged in the previous comment regarding the security plugin configuration.


104-116: LGTM! Container creation follows established patterns.

The implementation correctly:

  • Appends all options to moduleOpts (consistent with the Neo4j module pattern shown in relevant snippets)
  • Uses testcontainers.Run with the composed options
  • Stores credentials in the container struct for later use
  • Wraps errors with "run opensearch: %w" for clear error context

Note: Option instances are processed twice—once for settings extraction (lines 40-46) and once when Run calls Customize (which is a NOOP). This is intentional and consistent with the design where Option implements ContainerCustomizer but performs its work during settings extraction rather than in Customize.

Based on learnings from relevant code snippets showing the Neo4j module uses the same pattern.

@mdelapenya mdelapenya merged commit 1290c6f into testcontainers:main Oct 7, 2025
18 checks passed
@mdelapenya mdelapenya deleted the use-run-claude-opensearch branch October 7, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Causing compatibility issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant